<?php
/*
Plugin Name: XStandard
Plugin URI: http://contactsheet.de/xstandard.xhtml
Description: Integrates XStandard Editor into WordPress. XStandard is a standards-compliant, flexible and highly customizable WYSIWYG-solution. It ensures, the that your markup validates against XHTML 1.0 Strict and XHTML 1.1 specifications. Configure your WYSIWYGs on the <a href="options-general.php?page=xstandard.php">XStandard Options Page</a> (if you enable this feature, users can customize their WYSIWYG settings in their <a href="profile.php">Profile Page</a> or on a per post basis. 
Version: 0.5
Author: <a href="http://www.contactsheet.de/">Erik Pöhler</a>
Author URI: http://www.contactsheet.de/
Update Server: http://contactsheet.de/download/xstandard/
Min WP Version: 2.1
Max WP Version: 2.7.1
*/

/*__________________________________________________________________________________
 |                                                                                  |
 |   Copyright 2009  Erik Pöhler  (email : sayhello@erikpoehler.com)                |
 |                                                                                  |
 |   This program is free software; you can redistribute it and/or modify           |
 |   it under the terms of the GNU General Public License as published by           |
 |   the Free Software Foundation; either version 2 of the License, or              |
 |   (at your option) any later version.                                            |
 |                                                                                  |
 |   This program is distributed in the hope that it will be useful,                |
 |   but WITHOUT ANY WARRANTY; without even the implied warranty of                 |
 |   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                  |
 |   GNU General Public License for more details.                                   |
 |                                                                                  |
 |   You should have received a copy of the GNU General Public License              |
 |   along with this program; if not, write to the Free Software                    |
 |   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA      |
 |__________________________________________________________________________________|
*/

// don't do this at home kids
/*/
error_reporting(E_ALL); 
ini_set('display_errors', 1);
/**/
	if (!class_exists("XStandard")) {
		class XStandard {
			protected $adminOptionsName = "XStandardAdminOptions";
			protected $generalEditorOptionsName = "XStandardNeu4Options";
			static $bitmaskOptions = array('DISABLEHARDRETURNS'
				,'AUTOFIX'
				,'NOCONTEXTMENU'
				,'WRAPINSOURCE'
				,'NOLNINSOURCE'
				,'NOOBJRESIZING'
				,'UPLOADDECO'
				,'NIY'
				,'SPACES2HARDSPACES'
				,'NOADVANCEDEDITING'
				,'SOAP12'
				,'DIVSTRUCTURE'
				,'DISABLEDIRONSELECT'
				,'DISABLEPASTEFIX'
				,'REMOVENONSTANDARD'
				,'PASTEIMGASALT'
				,'STRICTPASTE'
				,'DISPLAYCLASSFIELD'
				,'DISPLAYIDFIELD');
			private $main;


			private function init() {
				$this->getAdminOptions();
				$this->getXStandardOptions();
			}


			// Constructor
			public function XStandard() {
				require_once realpath(dirname(__FILE__) . '/lib/php/XStandardConstants.script.php');
				$this->readVersionInformation();
				load_plugin_textdomain('xs', 'wp-content/plugins/' . XS_PLUGINDIR_NAME);
				require_once($_SERVER['DOCUMENT_ROOT']."/wp-content/plugins/xstandard/lib/php/bitmask.class.php");
				$this->main = new bitmask;
			}


			private function readVersionInformation() {
				// Get the readme.txt file contents
				$readmeContent = file_get_contents(realpath(dirname(__FILE__) . '/readme.txt'));
				
				// Since we don't want to execute regular expressions against the whole file, we extract the header part
				$readmeHeader = substr($readmeContent, 0, strpos($readmeContent, '== Description =='));
				
				// Extract the defined version numbers
				$this->pluginVersion = $this->_parseReadmeValue($readmeHeader, 'Stable tag');
				$this->requiredWordPressVersion = $this->_parseReadmeValue($readmeHeader, 'Requires at least');
				$this->highestTestedWordPressVersion = $this->_parseReadmeValue($readmeHeader, 'Tested up to');
				$this->xstandardVersionIncluded = $this->_parseReadmeValue($readmeHeader, 'XStandard Version included');
				$this->xstandardLatest = $this->_getVersionFile("http://xstandard.com/version/xstandard.txt", &$error, $timeout=10, $followredirects=true);
			}


			/** 
			 * Function extracts a value from the readme header
			 *
			 * @param string $readmeHeader
			 * @param string $key
			 * @return string
			 **/
			private function _parseReadmeValue($readmeHeader, $key) {
				preg_match('#' . $key . '\s*:\s*([0-9.]+)#i', $readmeHeader, $match);
				return $match[1];
			}


			private function URLreadFsock($host, $file, &$errstr, $successonly=true, $port=80, $timeout=10) {
				if (!function_exists('fsockopen')) {
					$errstr = 'fsockopen() unavailable';
					return false;
				}
				if ($fp = @fsockopen($host, 80, $errno, $errstr, $timeout)) {
					$out  = 'GET '.$file.' HTTP/1.0'."\r\n";
					$out .= 'Host: '.$host."\r\n";
					$out .= 'Connection: Close'."\r\n\r\n";
					fwrite($fp, $out);
		
					$isHeader = true;
					$Data_header = '';
					$Data_body   = '';
					$header_newlocation = '';
					while (!feof($fp)) {
						$line = fgets($fp, 1024);
						if ($isHeader) {
							$Data_header .= $line;
						} else {
							$Data_body .= $line;
						}
						if (eregi('^HTTP/[\\.0-9]+ ([0-9]+) (.+)$', rtrim($line), $matches)) {
							list($dummy, $errno, $errstr) = $matches;
							$errno = intval($errno);
						} elseif (eregi('^Location: (.*)$', rtrim($line), $matches)) {
							$header_newlocation = $matches[1];
						}
						if ($isHeader && ($line == "\r\n")) {
							$isHeader = false;
							if ($successonly) {
								switch ($errno) {
									case 200:
										// great, continue
										break;
		
									default:
										$errstr = $errno.' '.$errstr.($header_newlocation ? '; Location: '.$header_newlocation : '');
										fclose($fp);
										return false;
										break;
								}
							}
						}
					}
					fclose($fp);
					return $Data_body;
				}
				return null;
			}


			private function ParseURLbetter($url) {
				$parsedURL = @parse_url($url);
				if (!@$parsedURL['port']) {
					switch (strtolower(@$parsedURL['scheme'])) {
						case 'ftp':
							$parsedURL['port'] = 21;
							break;
						case 'https':
							$parsedURL['port'] = 443;
							break;
						case 'http':
							$parsedURL['port'] = 80;
							break;
					}
				}
				return $parsedURL;
			}


			// fetch the latest version of XStandard
			private function _getVersionFile($url, &$error, $timeout=10, $followredirects=true) {
				$error = '';
		
				$parsed_url = $this->ParseURLbetter($url);
				$alreadyLookedAtURLs[trim($url)] = true;
				
				while (true) {
					$tryagain = false;
					$rawData = $this->URLreadFsock(@$parsed_url['host'], @$parsed_url['path'].'?'.@$parsed_url['query'], $errstr, true, (@$parsed_url['port'] ? @$parsed_url['port'] : 80), $timeout);
					if (eregi('302 [a-z ]+; Location\\: (http.*)', $errstr, $matches)) {
						$matches[1] = trim(@$matches[1]);
						if (!@$alreadyLookedAtURLs[$matches[1]]) {
							// loop through and examine new URL
							$error .= 'URL "'.$url.'" redirected to "'.$matches[1].'"';
		
							$tryagain = true;
							$alreadyLookedAtURLs[$matches[1]] = true;
							$parsed_url = $this->ParseURLbetter($matches[1]);
						}
					}
					if (!$tryagain) {
						break;
					}
				}
				
				if ($rawData === false) {
					$error .= 'Error opening "'.$url.'":'."\n\n".$errstr;
					return false;
				} elseif ($rawData === null) {
					// fall through
					$error .= 'Error opening "'.$url.'":'."\n\n".$errstr;
				} else {
					return trim($rawData);
				}
				
				// curl
				if (function_exists('curl_version')) {
					$ch = curl_init();
					curl_setopt($ch, CURLOPT_URL, $url);
					curl_setopt($ch, CURLOPT_HEADER, false);
					curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
					curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
					curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
					$rawData = curl_exec($ch);
					curl_close($ch);
					if (strlen($rawData) > 0) {
						$error .= 'CURL succeeded ('.strlen($rawData).' bytes); ';
						return trim($rawData);
					}
					$error .= 'CURL available but returned no data; ';
				} else {
					$error .= 'CURL unavailable; ';
				}
				
				// fopen
				$BrokenURLfopenPHPversions = array('4.4.2');
				if (in_array(phpversion(), $BrokenURLfopenPHPversions)) {
					$error .= 'fopen(URL) broken in PHP v'.phpversion().'; ';
				} elseif (@ini_get('allow_url_fopen')) {
					$rawData = '';
					$error_fopen = '';
					ob_start();
					if ($fp = fopen($url, 'rb')) {
						do {
							$buffer = fread($fp, 8192);
							$rawData .= $buffer;
						} while (strlen($buffer) > 0);
						fclose($fp);
					} else {
						$error_fopen .= trim(strip_tags(ob_get_contents()));
					}
					ob_end_clean();
					$error .= $error_fopen;
					if (!$error_fopen) {
						$error .= '; "allow_url_fopen" succeeded ('.strlen($rawData).' bytes); ';
						return trim($rawData);
					}
					$error .= '; "allow_url_fopen" enabled but returned no data ('.$error_fopen.'); ';
				} else {
					$error .= '"allow_url_fopen" disabled; ';
				}
				return false;
			}


			// General XStandard Editor Settings
			private function getXStandardOptions() {
				// initial default settings
				$xsGeneralEditorOptions = array(
					 "EditorDefaultHeight"	=>		"420"
					,"BackgroundColor"		=> 		"#FFFFFF"
					,"BorderColor"			=> 		"#CCCCCC"
					,"Buttons"				=> 		"" // used to change icons and define buttons for the toolbar eg: XS_URL."lib/xml/default_buttons.xml" 
					,"ClassImageFloatLeft"	=> 		"align_left"
					,"ClassImageFloatRight"	=> 		"align_right"
					,"CSS" 					=> 		"" // XS_URL."lib/css/default.css" // can be the same CSS file used on your Web site
					,"CustomInlineElements"	=> 		"" // comma separated list
					,"CustomBlockElements"	=> 		"" // comma separated list
					,"CustomEmptyElements"	=> 		"more" // as XStandard doesn't support HTML comments. We use a custom element which we can str_replace on submit
					,"Debug"				=> 		"no" // provide an option to analyze possible problems 
					,"EditorCSS" 			=> 		"" // XS_URL."lib/css/default_wysiwyg.css" 			// wysiwyg only css rules
					,"EnableCache" 			=> 		"false" // TODO: add lastmod filestamp to affected values - affects CSS EditorCSS Styles Localization ScreenReaderXSLT PreviewXSLT Buttons Icons  Placeholders License
					,"EnableTimestamp"		=> 		"true" // want an XStandard comment in each posts source code?
					,"EnablePasteMarkup"	=> 		"true" // enable/disable copy/paste
					,"EscapeUnicode"		=>		"false" // true = escape non ascii chars (only needed for non UTF-8 CMS)
					,"ExpandWidth" 			=> 		"100%" // fullscreen mode or something?!
					,"ExpandHeight"			=>		"100%"
					,"ExpandToolbarWysiwyg"	=>		"ordered-list, unordered-list, definition-list,, draw-layout-table, draw-data-table, image, separator, hyperlink, attachment, directory, spellchecker,, wysiwyg, source, preview, screen-reader, help"
					,"ExpandToolbarSource"	=>		"ordered-list, unordered-list, definition-list,, draw-layout-table, draw-data-table, image, separator, hyperlink, attachment, directory, spellchecker,, wysiwyg, source, preview, screen-reader, help"
					,"ExpandToolbarPreview"	=>		"ordered-list, unordered-list, definition-list,, draw-layout-table, draw-data-table, image, separator, hyperlink, attachment, directory, spellchecker,, wysiwyg, source, preview, screen-reader, help"
					,"ExpandToolbarScreenReader"=>	"ordered-list, unordered-list, definition-list,, draw-layout-table, draw-data-table, image, separator, hyperlink, attachment, directory, spellchecker,, wysiwyg, source, preview, screen-reader, help"
					,"ExpandShowStyles" 	=> 		"true"
					,"ExpandShowToolbar"	=>		"true"
					,"HeartbeatURL"			=>		"" // TODO: probably not needed since wp doesn't use sessions and has its own autosave feature/interval
					,"HeartbeatInterval"	=>		300
					,"Icons"				=>		"" // XS_URL."lib/xml/default_icons.xml"
					,"IndentOutput"			=>		"yes"
					,"Lang"					=>		XS_LANG
					,"LatestVersion"		=>		$this->xstandardLatest
					,"License"				=>		"" // get your pro license at http://xstandard.com/
					,"Localization"			=>		"" // XS_URL."lib/l10n/l10n-".XS_LANG.".xml"
					,"Mode"					=>		"wysiwyg" // default mode
					,"Namespaces"			=>		""
					,"Options"				=>		2048
					,"Placeholders"			=>		"" // XS_URL."lib/xml/default_placeholders.xml"
					,"PreviewXSLT"			=>		"" // XS_URL."lib/xsl/default_preview.xsl"
					,"Rel"					=>		"me, contact, acquaintance, friend, met, co-worker, colleague, co-resident, neighbor, child, kin, parent, sibling, spouse, muse, crush, date, sweetheart"
					,"Rev"					=>		"me, contact, acquaintance, friend, met, co-worker, colleague, co-resident, neighbor, child, kin, parent, sibling, spouse, muse, crush, date, sweetheart"
					,"ScreenReaderXSLT"		=>		"" // XS_URL."lib/xsl/default_screenreader.xsl"
					,"Styles"				=>		"" // XS_URL."lib/xml/default_styles.xml" // IMPORTANT Markup information
					,"ShowStyles"			=> 		"true"
					,"ShowToolbar"			=>		"true"
					,"Toolbar"				=>		"ordered-list, unordered-list, definition-list,, draw-layout-table, draw-data-table, image, separator, hyperlink, attachment, directory, spellchecker,, wysiwyg, source, preview, screen-reader, help" // TODO: ajaxify this
					,"ToolbarWysiwyg"		=>		"ordered-list, unordered-list, definition-list,, draw-layout-table, draw-data-table, image, separator, hyperlink, attachment, directory, spellchecker,, wysiwyg, source, preview, screen-reader, help" // TODO: ajaxify this
					,"ToolbarSource"		=>		"ordered-list, unordered-list, definition-list,, draw-layout-table, draw-data-table, image, separator, hyperlink, attachment, directory, spellchecker,, wysiwyg, source, preview, screen-reader, help" // TODO: ajaxify this
					,"ToolbarPreview"		=>		"ordered-list, unordered-list, definition-list,, draw-layout-table, draw-data-table, image, separator, hyperlink, attachment, directory, spellchecker,, wysiwyg, source, preview, screen-reader, help" // TODO: ajaxify this
					,"ToolbarScreenReader"	=>		"ordered-list, unordered-list, definition-list,, draw-layout-table, draw-data-table, image, separator, hyperlink, attachment, directory, spellchecker,, wysiwyg, source, preview, screen-reader, help" // TODO: ajaxify this
					,"ToolbarEffect"		=>		"linear-gradient"
					,"ImageLibraryPath"		=>		get_option("upload_path")
					,"Version"				=>		$this->xstandardVersionIncluded // actually I'm just guessing here... and why the heck do i save this to the DB?
/** 
	Do I understand the following settings?
	Guess there's no real use in a browser-only environment, right?
 	maybe implement (on request) in future versions.
					,"DocumentID"			=> 		"" // additional HTTP header --- submits a header which is available on all requests for example in PHP via $_SERVER["HTTP_X_DOCUMENT_ID"]
					,"UserID"				=> 		"" // additional HTTP header
					,"SessionID"			=> 		"" // additional HTTP header
					,"TransactionID"		=> 		"" // additional HTTP header
					,"ClientID"				=> 		"" // additional HTTP header
					,"InstanceID"			=> 		"" // additional HTTP header
					,"TagID"				=> 		"" // additional HTTP header
					,"ZoneID"				=> 		"" // additional HTTP header
					,"ProjectID"			=> 		"" // additional HTTP header
					,"AreaID"				=> 		"" // additional HTTP header
					,"GroupID"				=> 		"" // additional HTTP header
					,"ParentID"				=> 		"" // additional HTTP header
					,"ContainerID"			=> 		"" // additional HTTP header
					,"ObjectID"				=> 		"" // additional HTTP header
**/
					,"CMSImageLibraryURL"	=> 		XS_URL."lib/php/cmsimagelibrary.php"
					,"ImageLibraryURL"		=> 		""
					,"CMSAttachmentLibraryURL" =>	XS_URL."lib/php/cmsattachmentlibrary.php"
					,"AttachmentLibraryURL" =>		XS_URL."lib/php/attachmentlibrary.php"
					,"SpellCheckerURL"		=> 		XS_URL."lib/php/spellchecker.php"
					,"SpellCheckerLangFilter" =>	"" // sub-set of the dictionaries eg: en-ca, fr
					,"SpellCheckerLang"		=>		"en-us"
					,"CMSDirectoryURL"		=>		XS_URL."lib/php/cmsdirectory.php"
					,"DirectoryURL"			=>		XS_URL."lib/php/directory.php"
					,"SubdocumentURL"		=>		XS_URL."lib/php/subdocument.php"
					,"ProxySetting"			=>		"auto-detect"
					,"ProxyServer"			=>		""
					,"ProxyPort"			=>		""
					,"ProxyUser"			=>		""
					,"ProxyPassword"		=>		""
				);
				$storedOptions = get_option($this->generalEditorOptionsName);
				if (!empty($storedOptions)) {
					foreach ($storedOptions as $key => $storedOptionValue)
						$xsGeneralEditorOptions[$key] = $storedOptionValue;
				}
				update_option($this->generalEditorOptionsName, $xsGeneralEditorOptions);
				return $xsGeneralEditorOptions;
			}

			// Returns an array of admin options
			private function getAdminOptions() {
				$xsAdminOptions = array('show_header' => 'true',
										'add_content' => 'true',
										'comment_author' => 'true',
										'content' => '');
				$_xsAdminOptions = get_option($this->adminOptionsName);
				/**/
				if (!empty($_xsAdminOptions)) {
					foreach ($_xsAdminOptions as $key => $option) {
						$xsAdminOptions[$key] = $option;
					}
				}
				/**/
				update_option($this->adminOptionsName, $xsAdminOptions);
				return $xsAdminOptions;
			}

			// helper function - handling POST vars
			private function get($key) {
				if (is_array($_POST) && array_key_exists($key, $_POST)) {
					if (is_array($_POST[$key])) {
						// loop through array
						$tmpArray = $_POST[$key];
						foreach ($tmpArray as $tmpKey => $tmpVal ) {
							if (ini_get("magic_quotes_gpc")==1) {
								$k = stripslashes(trim(htmlspecialchars($tmpKey)));
								$v = stripslashes(trim(htmlspecialchars($tmpVal)));
								$clean[$k] = $v;
							} else {
								$k = trim(htmlspecialchars($tmpKey));
								$v = trim(htmlspecialchars($tmpVal));
								$clean[$k] = $v;
							}
						}
						return $clean;
					} elseif (is_string($_POST[$key])) {
						// return string
						if (ini_get("magic_quotes_gpc")==1) {
							return stripslashes(trim(htmlspecialchars($pv[$key])));
						} else {
							return trim(htmlspecialchars($_POST[$key]));
						}
					}
				}
				return false;
			}

			// add JS to admin head
			public function _filter_js_admin_head () { ?>
				<link type="text/css" rel="stylesheet" href="<?php print XS_URL?>lib/css/xstandard-for-wordpress-admin.css" />
				<!--script type="text/javascript" src="<?php print XS_URL?>lib/js/jquery.hoverIntent.minified.js" /-->
				<script type="text/javascript">
				/* <![CDATA[ */
				<?php if (basename($_SERVER['PHP_SELF']) === "post-new.php" || basename($_SERVER['PHP_SELF']) === "post.php" || basename($_SERVER['PHP_SELF']) == "page-new.php" || basename($_SERVER['PHP_SELF']) == "page.php") { ?>
				(function($) {
					function fakeMissingHook() {
						var the_editor = $('#insert_xstandard').html();
						$('#titlediv').after(the_editor);
						$('#insert_xstandard').remove();
						// ehm... this depends on a user setting...
						$('#postdivrich').remove();
						$('#postdiv').remove();
						$('#clickme').click(function(){
							document.getElementById('editor1').EscapeUnicode = true;
							document.getElementById('content').value = document.getElementById('editor1').value;
							var curr_content = document.getElementById('content').value;
							alert(curr_content);
						});
						$("#post").submit(function(){
							document.getElementById('editor1').EscapeUnicode = true;
							// alert(curr_content);
							document.getElementById('content').value = document.getElementById('editor1').value;
							// alert(document.getElementById('content').value);
							return true;
						});
					}
					function displayOptionsHelp() {
						$("div.xs-options ol li input, div.xs-options ol li select").focus(
							function() {
								// $(this).parent().parent().find("li").removeClass("active");
								$(this).parent().parent().find("li div.helpbox").remove();
								$(this).parent().addClass('active').trigger('mouseover');
							}
						);
						$("div.xs-options ol li input, div.xs-options ol li select").blur(
							function() {
								$(this).parent().removeClass('active').trigger('mouseout');
							}
						);
						var config = {
							sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)
							interval: 200, // number = milliseconds for onMouseOver polling interval
							over: showHelp, // function = onMouseOver callback (REQUIRED)
							timeout: 500, // number = milliseconds delay before onMouseOut
							out: hideHelp // function = onMouseOut callback (REQUIRED)
						};
						$("div.xs-options ol li").hoverIntent(config);
					}
					function showHelp() {
						var helptxt = $(this).find("p").html();
						if (helptxt) {
							$(this).append('<div class="helpbox" style="display:block;opacity:0;"><div class="hb-inner">' + helptxt + '</div><div class="marker"></div></div>');
							var hb = $(this).find("div.helpbox");
							var ht = hb.height() - 10;
							hb.animate({opacity:"1"},300);
							hb.css({top:'-'+ht+'px'});
						}
					}
					function hideHelp() {
						$(this).find("div.helpbox").animate({opacity:"0"},300).css({display:"none"});
					}
					fakeMissingHook();
					displayOptionsHelp();
				})(jQuery);
				<?php } else { print "// XStandard was here. (but didn't do anything. You are at ".basename($_SERVER['PHP_SELF'])." so it doesn't seem like you'll want some JS from me)" .
						"\n"; } ?>
				/* ]]> */
				</script>
				
				<script type="text/javascript">
				<?php // TODO: jqueryfy this and replace redirection with a friendly notification or something
				?>
				//<![CDATA[
				(function($) {
					function updateXStandard() {
						var latestVersion = '<?php print $this->xstandardLatest?>';
						if (navigator.userAgent.toLowerCase().indexOf('firefox') != -1) {
							var objects = document.getElementsByTagName('object');
							for (var i=0; i<objects.length; i++) {
								var obj = objects[i];
								try {
									if(typeof(obj.EscapeUnicode) == 'undefined') {
										throw "Error"
									} else {
										if (obj.Version != latestVersion) {
											window.location.replace('http://xstandard.com/upgrade-firefox-version/');
											break;
										}
									}
								}
								catch(er) {}
							}
						}
					}
					updateXStandard();	
				})(jQuery);
				//]]>
				</script>
				<!--[if !IE]>-->
					<!--script type="text/javascript" src="<?php print XS_URL?>lib/js/xstandard.js"></script-->
				<!--<![endif]-->
			<?php
			}

			public function _filter_edit_form_advanced() {
				global $post;

				$opt = $this->getXStandardOptions();
				
				if ($this->get('post') && is_int(intval($this->get('post')))) {
					$this->postid = $this->get('post');
					$post = &get_post($this->postid);
				}
				
				$the_editor = "<!-- XStandard for WordPress was here! -->";
				$the_editor .= '<div id="insert_xstandard">'."\n";
				if (strlen($opt["EditorDefaultHeight"]) && is_int(intval($opt["EditorDefaultHeight"]))) { $editor_height = $opt["EditorDefaultHeight"]; } else { $editor_height = 420; }
				$the_editor .= '<object type="application/x-xstandard" name="editor1" id="editor1" width="100%" height="'.$editor_height.'" style="margin-bottom:15px;">'."\n";
				// TODO: clsid for the sake of IE7+ auto installation. classid="clsid:0EED7206-1661-11D7-84A3-00606744831D"
				
				// REMEMBER: not echoing parameters will have XStandard use its internal default. Make sure that's wanted in all cases.
				
				if(strlen($opt["BackgroundColor"])) {
					$the_editor .= '	<param name="BackgroundColor" value="'.$opt["BackgroundColor"].'" />'."\n";
				}
				if(strlen($opt["BorderColor"])) {
					$the_editor .= '	<param name="BorderColor" value="'.$opt["BorderColor"].'" />'."\n";
				}
				$the_editor .= '	<param name="Base" value="'.trailingslashit(get_bloginfo("url")).'" />'."\n";
				
				if(strlen($opt["Buttons"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["Buttons"]))) {
					$the_editor .= '	<param name="Buttons" value="'.wp_make_link_relative($opt["Buttons"]).'" />'."\n";
				}
				if(strlen($opt["ClassImageFloatLeft"])) {
					$the_editor .= '	<param name="ClassImageFloatLeft" value="'.$opt["ClassImageFloatLeft"].'" />'."\n";
				}
				if(strlen($opt["ClassImageFloatRight"])) {
					$the_editor .= '	<param name="ClassImageFloatRight" value="'.$opt["ClassImageFloatRight"].'" />'."\n";
				}
				if(strlen($opt["License"])<1) {
				/* no need for this if a license file is present.
				 * (this effectively turns XStandard Lite into XStandard half pro OSCMS mode)
				 * note: Who the fuck is Joomla? Come on Belus! Don't piss off the WordPress community! 
				 */
					$the_editor .= '	<param name="CMSCode" value="065126D6-357D-46FC-AF74-A1F5B2D5036E" />'."\n";
				}
				// $the_editor .= '	<param name="Cookie" value="" />'."\n";
				if(strlen($opt["CSS"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["CSS"]))) {
					$the_editor .= '	<param name="CSS" value="'.wp_make_link_relative($opt["CSS"]).'" />'."\n";
				}
				if(strlen($opt["CustomInlineElements"])) {
					$the_editor .= '	<param name="CustomInlineElements" value="'.$opt["CustomInlineElements"].'" />'."\n";
				}
				if(strlen($opt["CustomBlockElements"])) {
					$the_editor .= '	<param name="CustomBlockElements" value="'.$opt["CustomBlockElements"].'" />'."\n";
				}
				if(strlen($opt["CustomEmptyElements"])) {
					$the_editor .= '	<param name="CustomEmptyElements" value="'.$opt["CustomEmptyElements"].'" />'."\n";
				}
				if(strlen($opt["Debug"])) {
					$the_editor .= '	<param name="Debug" value="'.$opt["Debug"].'" />'."\n";
				}
				$the_editor .= '	<param name="Dir" value="'.get_bloginfo('text_direction').'" />'."\n";
				if(strlen($opt["EditorCSS"])) {
					$the_editor .= '	<param name="EditorCSS" value="'.$opt["EditorCSS"].'" />'."\n";
				}
				if(strlen($opt["EnableCache"])) {
					$the_editor .= '	<param name="EnableCache" value="'.$opt["EnableCache"].'" />'."\n";
				}
				if(strlen($opt["EnablePasteMarkup"])) {
					$the_editor .= '	<param name="EnablePasteMarkup" value="'.$opt["EnablePasteMarkup"].'" />'."\n";
				}
				if(strlen($opt["EnableTimestamp"])) {
					$the_editor .= '	<param name="EnableTimestamp" value="'.$opt["EnableTimestamp"].'" />'."\n";
				}
				if(strlen($opt["EscapeUnicode"])) {
					$the_editor .= '	<param name="EscapeUnicode" value="'.$opt["EscapeUnicode"].'" />'."\n";
				}
				if(strlen($opt["ExpandWidth"])) {
					$the_editor .= '	<param name="ExpandWidth" value="'.$opt["ExpandWidth"].'" />'."\n";
				}
				if(strlen($opt["ExpandHeight"])) {
					$the_editor .= '	<param name="ExpandHeight" value="'.$opt["ExpandHeight"].'" />'."\n";
				}
				if(strlen($opt["ExpandToolbarWysiwyg"])) {
					$the_editor .= '	<param name="ExpandToolbarWysiwyg" value="'.$opt["ExpandToolbarWysiwyg"].'" />'."\n";
				}
				if(strlen($opt["ExpandToolbarSource"])) {
					$the_editor .= '	<param name="ExpandToolbarSource" value="'.$opt["ExpandToolbarSource"].'" />'."\n";
				}
				if(strlen($opt["ExpandToolbarPreview"])) {
					$the_editor .= '	<param name="ExpandToolbarPreview" value="'.$opt["ExpandToolbarPreview"].'" />'."\n";
				}
				if(strlen($opt["ExpandToolbarScreenReader"])) {
					$the_editor .= '	<param name="ExpandToolbarScreenReader" value="'.$opt["ExpandToolbarScreenReader"].'" />'."\n";
				}
				if(strlen($opt["ExpandShowStyles"])) {
					$the_editor .= '	<param name="ExpandShowStyles" value="'.$opt["ExpandShowStyles"].'" />'."\n";
				}
				if(strlen($opt["ExpandShowToolbar"])) {
					$the_editor .= '	<param name="ExpandShowToolbar" value="'.$opt["ExpandShowToolbar"].'" />'."\n";
				}
				if(strlen($opt["HeartbeatURL"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["HeartbeatURL"]))) {
					$the_editor .= '	<param name="HeartbeatURL" value="'.$opt["HeartbeatURL"].'" />'."\n";
					if(strlen($opt["HeartbeatInterval"])) {
						$the_editor .= '	<param name="HeartbeatInterval" value="'.$opt["HeartbeatInterval"].'" />'."\n";
					}
				}
				if(strlen($opt["Icons"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["Icons"]))) {
					$the_editor .= '	<param name="Icons" value="'.wp_make_link_relative($opt["Icons"]).'" />'."\n";
				}
				if(strlen($opt["IndentOutput"])) {
					$the_editor .= '	<param name="IndentOutput" value="'.$opt["IndentOutput"].'" />'."\n";
				}
				$the_editor .= '	<param name="Lang" value="'.XS_LANG.'" />'."\n";
				$the_editor .= '	<param name="LatestVersion" value="'.$this->xstandardLatest.'" />'."\n";
				if(strlen($opt["License"])>0) {
					$the_editor .= '	<param name="License" value="'.$opt["License"].'" />'."\n";
				}
				// TODO: use file based localization as override option. Better: l10n via .pot/.mo
				if(strlen($opt["Localization"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["Localization"]))) {
					$the_editor .= '	<param name="Localization" value="'.wp_make_link_relative($opt["Localization"]).'" />'."\n";
				}
				if(is_array($opt["Mode"])&&count($opt["Mode"])>0) {
					$the_editor .= '	<param name="Mode" value="'.$opt["Mode"].'" />'."\n";
				}
				if(strlen($opt["Namespaces"])) {
					$the_editor .= '	<param name="Namespaces" value="'.$opt["Namespaces"].'" />'."\n"; // syntax example: xmlns:a='http://apple-books' xmlns:b='http://big-books'
				}
				if(strlen($opt["Options"]) && is_int($opt["Options"])) {
					$the_editor .= '	<param name="Options" value="'.$opt["Options"].'" />'."\n";
				}
				if(strlen($opt["Placeholders"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["Placeholders"]))) {
					$the_editor .= '	<param name="Placeholders" value="'.wp_make_link_relative($opt["Placeholders"]).'" />'."\n";
				}
				if(strlen($opt["PreviewXSLT"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["PreviewXSLT"]))) {
					$the_editor .= '	<param name="PreviewXSLT" value="'.wp_make_link_relative($opt["PreviewXSLT"]).'" />'."\n";
				}
				if(strlen($opt["Rel"])) {
					$the_editor .= '	<param name="Rel" value="'.$opt["Rel"].'" />'."\n";
				}
				if(strlen($opt["Rev"])) {
					$the_editor .= '	<param name="Rev" value="'.$opt["Rev"].'" />'."\n";
				}
				if(strlen($opt["ScreenReaderXSLT"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["ScreenReaderXSLT"]))) {
					$the_editor .= '	<param name="ScreenReaderXSLT" value="'.wp_make_link_relative($opt["ScreenReaderXSLT"]).'" />'."\n";
				}
				// $the_editor .= '	<param name="ScriptNewWindow" value="" />'."\n"; bad. use a class and unobstrusive js to solve shortcomings here
				if(strlen($opt["Styles"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["Styles"]))) {
					$the_editor .= '	<param name="Styles" value="'.wp_make_link_relative($opt["Styles"]).'" />'."\n";
				}
				$the_editor .= '	<param name="ShowStyles" value="'.$opt["ShowStyles"].'" />'."\n";
				$the_editor .= '	<param name="ShowToolbar" value="'.$opt["ShowToolbar"].'" />'."\n";
				$the_editor .= '	<param name="Toolbar" value="'.$opt["Toolbar"].'" />'."\n";
				$the_editor .= '	<param name="ToolbarWysiwyg" value="'.$opt["ToolbarWysiwyg"].'" />'."\n";
				$the_editor .= '	<param name="ToolbarSource" value="'.$opt["ToolbarSource"].'" />'."\n";
				$the_editor .= '	<param name="ToolbarPreview" value="'.$opt["ToolbarPreview"].'" />'."\n";
				$the_editor .= '	<param name="ToolbarScreenReader" value="'.$opt["ToolbarScreenReader"].'" />'."\n";
				if(strlen($opt["ToolbarEffect"])) { // a fancy gradient? tsss
					$the_editor .= '	<param name="ToolbarEffect" value="'.$opt["ToolbarEffect"].'" />'."\n";
				}
				/* trying to get the posts content */
				if (!seems_utf8($post->post_content)) {
					$err_msg = "<small>WordPress thinks that this post was not encoded in UTF-8 format.</small>";
				};
				
				// retriev post content
				$xs_content = $post->post_content;
				if ((strlen(trim($xs_content))<1 || strtolower(trim($xs_content)) === "undefined") && strlen($post->post_content_filtered)>0 ) {
					$xs_content = $post->post_content_filtered;
				}
				if (!seems_utf8($xs_content)) {
					$msg2 = "not UTF-8";
				}
				// if a post has been edited by xstandard before, minimal check required here.
				if ("yes" === get_post_meta($_GET['post'], "edited_with_xstandard", true)) {
					// do nothing?
				} else {
					// if this is not an xstandard-edited article. we need to fix its markup.
					if (seems_utf8($post->post_content) && strlen($post->post_content)>0) {
						$xs_content = wpautop($xs_content);
						$xs_content = force_balance_tags($xs_content);
						$xs_content = $this->fixCode($xs_content);
						$xs_content = str_replace("<?","&lt;?",$xs_content);
					}
				}
				
				$xs_content = htmlspecialchars($xs_content); // always do this
				
				if (strlen($xs_content)<1) {
					// "Houston, we have a problem... (or its simply a new post)"
					// die("kein inhalt in content - keiner in content_filtered - was nun?");
				}
				$the_editor .= '	<param name="Value" value="'.$xs_content.'" />'."\n";
				if(strlen($opt["Version"])) {
					$the_editor .= '	<param name="Version" value="'.$opt["Version"].'" />'."\n";
				}

				/** not implemented yet: sending additional http headers 
				 * submits a header which is available on all requests e.g. via php with $_SERVER["HTTP_X_DOCUMENT_ID"]
				 */

/**				if(strlen($opt["DocumentID"])) {
					$the_editor .= '	<param name="DocumentID" value="" />'."\n";
				}
				if(strlen($opt["UserID"])) {
					$the_editor .= '	<param name="UserID" value="" />'."\n";
				}
				if(strlen($opt["SessionID"])) {
					$the_editor .= '	<param name="SessionID" value="" />'."\n";
				}
				if(strlen($opt["TransactionID"])) {
					$the_editor .= '	<param name="TransactionID" value="" />'."\n";
				}
				if(strlen($opt["ClientID"])) {
					$the_editor .= '	<param name="ClientID" value="" />'."\n";
				}
				if(strlen($opt["InstanceID"])) {
					$the_editor .= '	<param name="InstanceID" value="" />'."\n";
				}
				if(strlen($opt["TagID"])) {
					$the_editor .= '	<param name="TagID" value="" />'."\n";
				}
				if(strlen($opt["ZoneID"])) {
					$the_editor .= '	<param name="ZoneID" value="" />'."\n";
				}
				if(strlen($opt["ProjectID"])) {
					$the_editor .= '	<param name="ProjectID" value="" />'."\n";
				}
				if(strlen($opt["AreaID"])) {
					$the_editor .= '	<param name="AreaID" value="" />'."\n";
				}
				if(strlen($opt["GroupID"])) {
					$the_editor .= '	<param name="GroupID" value="" />'."\n";
				}
				if(strlen($opt["ParentID"])) {
					$the_editor .= '	<param name="ParentID" value="" />'."\n";
				}
				if(strlen($opt["ContainerID"])) {
					$the_editor .= '	<param name="ContainerID" value="" />'."\n";
				}
				if(strlen($opt["ObjectID"])) {
					$the_editor .= '	<param name="ObjectID" value="" />'."\n";
				}
				/** end additional http header **/

				/** start server-side applications **/ 
				// pro
				if(strlen($opt["License"])>0 && strlen($opt["ImageLibraryURL"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["ImageLibraryURL"]))) {
					$the_editor .= '	<param name="ImageLibraryURL" value="'.$opt["ImageLibraryURL"].'" />'."\n";
				}
				// oscms
				if(strlen($opt["License"])<1 && strlen($opt["CMSImageLibraryURL"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["CMSImageLibraryURL"]))) {
					$the_editor .= '	<param name="CMSImageLibraryURL" value="'.$opt["CMSImageLibraryURL"].'" />'."\n";
				}
				// pro
				if(strlen($opt["License"])>0 && strlen($opt["AttachmentLibraryURL"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["AttachmentLibraryURL"]))) {
					$the_editor .= '	<param name="AttachmentLibraryURL" value="'.$opt["AttachmentLibraryURL"].'" />'."\n";
				}
				// oscms
				if(strlen($opt["License"])<1 && strlen($opt["CMSAttachmentLibraryURL"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["CMSAttachmentLibraryURL"]))) {
					$the_editor .= '	<param name="CMSAttachmentLibraryURL" value="'.$opt["CMSAttachmentLibraryURL"].'" />'."\n";
				}
				if(strlen($opt["License"])>0 && strlen($opt["SpellCheckerURL"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["SpellCheckerURL"]))) {
					$the_editor .= '	<param name="SpellCheckerURL" value="'.$opt["SpellCheckerURL"].'" />'."\n";
					if(strlen($opt["SpellCheckerLangFilter"])) {
						$the_editor .= '	<param name="SpellCheckerLangFilter" value="'.$opt["SpellCheckerLangFilter"].'" />'."\n";
					}
					switch(true) {
						// if neither xstandard spellchecker language nor WPLANG is set default to english
						case (strlen(WPLANG) < 1 && strlen($opt["SpellCheckerLang"]) < 1 ):
							$sclang = "en-us";
							break;
						// if WPLANG is set. use it. I assume we want the current language over the one set in the options.
						case (strlen(WPLANG) > 1):
							$sclang = WPLANG;
							break;
						default:
							$sclang = $opt["SpellCheckerLang"];
							break;
					}
					if(strlen($opt["SpellCheckerLang"])) {
						$the_editor .= '	<param name="SpellCheckerLang" value="'.$sclang.'" />'."\n";
					}
				}
				// pro
				if(strlen($opt["License"])>0 && strlen($opt["DirectoryURL"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["DirectoryURL"]))) {
					$the_editor .= '	<param name="DirectoryURL" value="'.$opt["DirectoryURL"].'" />'."\n";
				}
				// oscms
				if(strlen($opt["License"])<1 && strlen($opt["CMSDirectoryURL"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["CMSDirectoryURL"]))) {
					$the_editor .= '	<param name="CMSDirectoryURL" value="'.$opt["CMSDirectoryURL"].'" />'."\n";
				}
				if(strlen($opt["License"])>0 && strlen($opt["SubdocumentURL"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["SubdocumentURL"]))) {
					$the_editor .= '	<param name="SubdocumentURL" value="'.$opt["SubdocumentURL"].'" />'."\n";
				}
				/** end server-side applications **/
				
				/** start proxy settings **/
				if(strlen($opt["ProxySetting"])) {
					$the_editor .= '	<param name="ProxySetting" value="'.$opt["ProxySetting"].'" />'."\n";
				}
				if($opt["ProxySetting"] === 'manual') {
					if(strlen($opt["ProxyServer"])) {
						$the_editor .= '	<param name="ProxyServer" value="'.$opt["ProxyServer"].'" />'."\n";
					}
					if(strlen($opt["ProxyPort"])) {
						$the_editor .= '	<param name="ProxyPort" value="'.$opt["ProxyPort"].'" />'."\n";
					}
					if(strlen($opt["ProxyUser"])) {
						$the_editor .= '	<param name="ProxyUser" value="'.$opt["ProxyUser"].'" />'."\n";
					}
					if(strlen($opt["ProxyPassword"])) {
						$the_editor .= '	<param name="ProxyPassword" value="'.$opt["ProxyPassword"].'" />'."\n";
					}
				}
				/** end proxy settings **/
				$the_editor .= '	<span>If you do not see the editor here, you have not yet installed XStandard to your computer. Before proceeding, please download XStandard from <a href="http://xstandard.com">http://xstandard.com</a></span>';
				$the_editor .= '</object>';
				$the_editor .= '</div>' .
						'<input type="hidden" id="content" name="content" value="" />' .
						'<!--div id="clickme" class="debugging thing" style="background:red; width:10px; height:10px;" title="click me!"></div-->';
				print $the_editor;
				print $err_msg;
				print $msg2;
				/**
				$dummyvar = get_post_meta($_GET['post'], "edited_with_xstandard", true);
				print '$post: <textarea style="width:100%;height:500px;">';
				print($dummyvar);
				print "</textarea>";
				
				
				print '$post: <textarea style="width:100%;height:500px;">';
				print_r($post);
				print "</textarea>";
				
				if ("yes" !== get_post_meta($_GET['post'], "edited_with_xstandard", true)) {
					print 'step 1 (raw data from db): <textarea style="width:100%;height:500px;">';
					print $step1;
					print "</textarea>";
					
					print 'step 2 (force_balance_tags): <textarea style="width:100%;height:500px;">';
					print $step2;
					print "</textarea>";
					
					print 'step 3 (wpautop): <textarea style="width:100%;height:500px;">';
					print $step3;
					print "</textarea>";
					
					print 'step 4 (fixCode): <textarea style="width:100%;height:500px;">';
					print $step4;
					print "</textarea>";
					
					print 'step 5 (wp_specialchars): <textarea style="width:100%;height:500px;">';
					print $step5;
					print "</textarea>";
					
					print 'step 6 (<samp>\<\? -> &lt;?</samp>): <textarea style="width:100%;height:500px;">';
					print $step6;
					print "</textarea>";
					
				}
				**/
			}
			
			// Options Page
			public function xsOptionsPage() {
				//$this->postvars = $_POST;
				// first we handle submitted POST vars

				// 1. General Plugin and Admin Options
				$_xsAdminOptions = $this->getAdminOptions();
				
				if ($this->get('update_adminSettings')) {
					// if ($this->get('xsHeader')) {
						$_xsAdminOptions['show_header'] = "false";
					//}
					if ($this->get('xsAddContent')) {
						$_xsAdminOptions['add_content'] = "false";
					}
					if ($this->get('xsAuthor')) {
						$_xsAdminOptions['comment_author'] = "Erik";
					}
					if ($this->get('xsContent')) {
						$_xsAdminOptions['content'] = "TEST!";
					}
					update_option($this->adminOptionsName, $_xsAdminOptions);
?>
					<div class="updated">
						<p>
							<strong><?php print __("Your general rich editing options have been updated.", 'xs');?></strong>
						</p>
					</div>
<?php 			}

				// 2. XStandard Customizations
				// getting the settings once here.
				$_xsOptions = $this->getXStandardOptions();
				
				if (isset($_POST['update_xsSettings'])) {
					/*
					now overwrite stored settings with submitted values 
					*/
					if (isset($_POST['EditorDefaultHeight'])) {
						$_xsOptions['EditorDefaultHeight'] = $_POST['EditorDefaultHeight'];
					}
					if (isset($_POST['BackgroundColor'])) {
						$_xsOptions['BackgroundColor'] = $_POST['BackgroundColor'];
					}
					if (isset($_POST['BorderColor'])) {
						$_xsOptions['BorderColor'] = $_POST['BorderColor'];
					}
					if (isset($_POST['Buttons'])) {
						$_xsOptions['Buttons'] = $_POST['Buttons'];
					}
					if (isset($_POST['ClassImageFloatLeft'])) {
						$_xsOptions['ClassImageFloatLeft'] = $_POST['ClassImageFloatLeft'];
				 	}
				 	if (isset($_POST['ClassImageFloatRight'])) {
						$_xsOptions['ClassImageFloatRight'] = $_POST['ClassImageFloatRight'];
				 	}
				 	if (isset($_POST['CSS'])) {
						$_xsOptions['CSS'] = $_POST['CSS'];
				 	}
				 	if (isset($_POST['CustomInlineElements'])) {
						$_xsOptions['CustomInlineElements'] = $_POST['CustomInlineElements'];
				 	}
				 	if (isset($_POST['CustomBlockElements'])) {
						$_xsOptions['CustomBlockElements'] = $_POST['CustomBlockElements'];
				 	}
				 	if (isset($_POST['CustomEmptyElements'])) {
						$_xsOptions['CustomEmptyElements'] = $_POST['CustomEmptyElements'];
				 	}
				 	if (isset($_POST['Debug'])) {
						$_xsOptions['Debug'] = $_POST['Debug'];
				 	}
				 	if (isset($_POST['EditorCSS'])) {
						$_xsOptions['EditorCSS'] = $_POST['EditorCSS'];
				 	}
				 	if (isset($_POST['EnableCache'])) {
						$_xsOptions['EnableCache'] = $_POST['EnableCache'];
				 	}
				 	if (isset($_POST['EnableTimestamp'])) {
						$_xsOptions['EnableTimestamp'] = $_POST['EnableTimestamp'];
				 	}
				 	if (isset($_POST['EnablePasteMarkup'])) {
						$_xsOptions['EnablePasteMarkup'] = $_POST['EnablePasteMarkup'];
				 	}
				 	if (isset($_POST['EscapeUnicode'])) {
						$_xsOptions['EscapeUnicode'] = $_POST['EscapeUnicode'];
				 	}
				 	if (isset($_POST['ExpandWidth'])) {
						$_xsOptions['ExpandWidth'] = $_POST['ExpandWidth'];
				 	}
				 	if (isset($_POST['ExpandHeight'])) {
						$_xsOptions['ExpandHeight'] = $_POST['ExpandHeight'];
				 	}
				 	if (isset($_POST['ExpandToolbarWysiwyg'])) {
						$_xsOptions['ExpandToolbarWysiwyg'] = $_POST['ExpandToolbarWysiwyg'];
				 	}
				 	if (isset($_POST['ExpandToolbarSource'])) {
						$_xsOptions['ExpandToolbarSource'] = $_POST['ExpandToolbarSource'];
				 	}
				 	if (isset($_POST['ExpandToolbarPreview'])) {
						$_xsOptions['ExpandToolbarPreview'] = $_POST['ExpandToolbarPreview'];
				 	}
				 	if (isset($_POST['ExpandToolbarScreenReader'])) {
						$_xsOptions['ExpandToolbarScreenReader'] = $_POST['ExpandToolbarScreenReader'];
				 	}
				 	if (isset($_POST['ExpandShowStyles'])) {
						$_xsOptions['ExpandShowStyles'] = $_POST['ExpandShowStyles'];
				 	}
				 	if (isset($_POST['ExpandShowToolbar'])) {
						$_xsOptions['ExpandShowToolbar'] = $_POST['ExpandShowToolbar'];
				 	}
				 	if (isset($_POST['HeartbeatURL'])) {
				 		$_xsOptions['HeartbeatURL'] = clean_url( $_POST['HeartbeatURL'], null );
				 	}
				 	if (isset($_POST['HeartbeatInterval'])) {
						$_xsOptions['HeartbeatInterval'] = intval($_POST['HeartbeatInterval']);
				 	}
				 	if (isset($_POST['Icons'])) {
						$_xsOptions['Icons'] = $_POST['Icons'];
				 	}
				 	if (isset($_POST['IndentOutput'])) {
						$_xsOptions['IndentOutput'] = $_POST['IndentOutput'];
				 	}
				 	if (isset($_POST['Lang'])) {
						$_xsOptions['Lang'] = $_POST['Lang'];
				 	}
				 	if (isset($_POST['LatestVersion'])) {
						$_xsOptions['LatestVersion'] = $_POST['LatestVersion'];
				 	}
				 	if (isset($_POST['License'])) {
						$_xsOptions['License'] = $_POST['License'];
				 	}
				 	if (isset($_POST['Localization'])) {
						$_xsOptions['Localization'] = $_POST['Localization'];
				 	}
				 	if (isset($_POST['Mode'])) {
						$_xsOptions['Mode'] = $_POST['Mode'];
				 	}
				 	if (isset($_POST['Namespaces'])) {
						$_xsOptions['Namespaces'] = $_POST['Namespaces'];
				 	}
				 	if (isset($_POST['DISABLEHARDRETURNS'])) {
						$_xsOptions['DISABLEHARDRETURNS'] = $_POST['DISABLEHARDRETURNS'];
				 	}

				 	if (isset($_POST['AUTOFIX'])) {
						$_xsOptions['AUTOFIX'] = $_POST['AUTOFIX'];
				 	}
				 	if (isset($_POST['NOCONTEXTMENU'])) {
						$_xsOptions['NOCONTEXTMENU'] = $_POST['NOCONTEXTMENU'];
				 	}
				 	if (isset($_POST['WRAPINSOURCE'])) {
						$_xsOptions['WRAPINSOURCE'] = $_POST['WRAPINSOURCE'];
				 	}
				 	if (isset($_POST['WRAPINSOURCE'])) {
						$_xsOptions['WRAPINSOURCE'] = $_POST['WRAPINSOURCE'];
				 	}
				 	if (isset($_POST['NOOBJRESIZING'])) {
						$_xsOptions['NOOBJRESIZING'] = $_POST['NOOBJRESIZING'];
				 	}
				 	if (isset($_POST['UPLOADDECO'])) {
						$_xsOptions['UPLOADDECO'] = $_POST['UPLOADDECO'];
				 	}
				 	if (isset($_POST['NIY'])) {
						$_xsOptions['NIY'] = $_POST['NIY'];
				 	}
				 	if (isset($_POST['SPACES2HARDSPACES'])) {
						$_xsOptions['SPACES2HARDSPACES'] = $_POST['SPACES2HARDSPACES'];
				 	}
				 	if (isset($_POST['NOADVANCEDEDITING'])) {
						$_xsOptions['NOADVANCEDEDITING'] = $_POST['NOADVANCEDEDITING'];
				 	}
				 	if (isset($_POST['SOAP12'])) {
						$_xsOptions['SOAP12'] = $_POST['SOAP12'];
				 	}
				 	if (isset($_POST['DIVSTRUCTURE'])) {
						$_xsOptions['DIVSTRUCTURE'] = $_POST['DIVSTRUCTURE'];
				 	}
				 	if (isset($_POST['DISABLEDIRONSELECT'])) {
						$_xsOptions['DISABLEDIRONSELECT'] = $_POST['DISABLEDIRONSELECT'];
				 	}
				 	if (isset($_POST['DISABLEPASTEFIX'])) {
						$_xsOptions['DISABLEPASTEFIX'] = $_POST['DISABLEPASTEFIX'];
				 	}
				 	if (isset($_POST['REMOVENONSTANDARD'])) {
						$_xsOptions['REMOVENONSTANDARD'] = $_POST['REMOVENONSTANDARD'];
				 	}
				 	if (isset($_POST['PASTEIMGASALT'])) {
						$_xsOptions['PASTEIMGASALT'] = $_POST['PASTEIMGASALT'];
				 	}
				 	if (isset($_POST['STRICTPASTE'])) {
						$_xsOptions['STRICTPASTE'] = $_POST['STRICTPASTE'];
				 	}
				 	if (isset($_POST['DISPLAYCLASSFIELD'])) {
						$_xsOptions['DISPLAYCLASSFIELD'] = $_POST['DISPLAYCLASSFIELD'];
				 	}
				 	if (isset($_POST['DISPLAYIDFIELD'])) {
						$_xsOptions['DISPLAYIDFIELD'] = $_POST['DISPLAYIDFIELD'];
				 	}
				 	
				 	
					// updating options so that new values are stored permanently
					update_option($this->generalEditorOptionsName, $_xsOptions);
					/**
					print "<pre>";
					print_r($_POST);
					print "</pre>";
					**/
?>
					<div class="updated">
						<p>
							<strong><?php print __("Your XStandard configuration has been updated.", 'xs')?></strong>
						</p>
					</div>
<?php } ?>


				<style type="text/css">div.xs label {display:block;}</style>
				<div class="wrap xs" id="wrapper">
					<div id="icon-options-general" class="icon32"><br /></div> 
						<h2 style="margin-top:-5px;"><img src="<?php print XS_URL?>lib/l10n/logo-xstandard-<?php print XS_LANG?>.gif" alt="<?php print _e("XStandard for WordPress",'xs');?>" /></h2>
						<p class="intro"><?php _e("This plugin adds a highly customizable WYSIWYG-editor (by the name of <em>XStandard</em>) to your WordPress installation. It is known for being fully compliant with XHTML standards and even copes with ugly formatted text, your editors love to paste directly from MS Word.","xs"); ?></p>
					<div class="leftcol">
						<div class="box intro">
						<h3><?php print __('General Rich Editing Options','xs')?></h3>
						<form method="post" action="<?php print $_SERVER["REQUEST_URI"]?>">
							<ol>
								<li>Allow users to switch their editor? yes|no</li>
								<li>Allow users to customize XStandard? yes|no</li>
								<li>Define a default editor for newly registered users. Which one?</li>
								<li>other options? (fewer is better)</li>
							</ol>
							<p>
								<input type="hidden" name="update_adminSettings" value="bla" />
								<input class="button-primary" type="submit" name="update_adminSettings" value="<?php print __("Save Rich Editing Options","xs")?>" />
								<input class="button" type="reset" name="restore_adminSettings" value="<?php print __("Restore Defaults","xs")?>" />
							</p>
						</form>
						</div>
						
						<div class="box credits">
							<h3><?php print __('Plugin-Information and Credits','xs')?>:</h3>
							<ul>
								<li><?php print __('Plugin-Author','xs')?>: <a href="http://contactsheet.de/">Erik P&ouml;hler</a>, Plugin-Version: <?=$this->pluginVersion?></li>
								<li><?php print __('Plugin-Homepage','xs')?>: <a href="http://contactsheet.de/plugins/xstandard-for-wordpress.xhtml" title="<?php print __('Plugin-Homepage','xs')?>"><?php print __('XStandard for WordPress','xs')?></a> (<?php print __('Documentation, Demonstration, Updates','xs')?>)</li>
								<li><?php print __('Download XStandard (required once)','xs')?>:<br /><a href="http://xstandard.com/download/x-lite.dmg" rel="nofollow">XStandard Lite for Mac OS X</a><br />
									<a href="http://xstandard.com/download/x-lite.exe" rel="nofollow">XStandard Lite for Windows</a>
								</li>
								<li><?php print __('<strong>Credits</strong>: Thanks to Belus Technology for creating a great piece of software. This open source project is hosted on <a href="http://code.google.com/p/xstandard-for-wordpress/" title="Project Home at Google Code">Google Code</a>. Parts of the code are inspired/lend out by the YAPB plugin.','xs')?></li>
								<li><?php print __('<strong>Show some love</strong>: If you like this plugin, consider a donation. Seriously, it was an amazing amount of work. Click the "Donate"-Button and choose the desired amount.','xs');?> 
								<form id="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
									<input type="hidden" name="cmd" value="_s-xclick">
									<input type="hidden" name="hosted_button_id" value="3974196">
									<input type="image" src="https://www.paypal.com/en_US/DE/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
									<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
								</form>
								<a href="http://www.amazon.com/wishlist/2ZCVQRCBRDAI5/ref=wl_web"><img src="http://g-ecx.images-amazon.com/images/G/01/gifts/registries/wishlist/v2/web/wl-btn-74-b._V46774601_.gif" width="74" alt="My Amazon.com Wish List" height="42" border="0" /></a>
								</li>
								<li><?php print __('You might also want get a XStandard Pro license to enjoy all of this WYSIWYGs features.<br />' .
										'Also you can contribute to this plugin (for example by submitting error tickets <a href="http://code.google.com/p/xstandard-for-wordpress/">here</a>).<br />Developers can checkout the latest trunk here:','xs')?> <input id="rss-combiner-svn" class="text" type="text" readonly="readonly" size="48" title="Subversion Access|Copy and paste this URL to your SVN-Client" value="http://xstandard-for-wordpress.googlecode.com/svn/trunk/" /></li></li>
								<li><?php print __('Plugin-License','xs')?>: <a href="http://creativecommons.org/licenses/GPL/2.0/deed.<?php print XS_LANG?>" title="Creative Commons GNU General Public License">GNU GPL</a></li>
							</ul>
							<p>
								
							</p>
						</div>
					</div>
					<div class="rightcol">	
						<?php $_xsOptions = $this->getXStandardOptions(); ?>
						<form method="post" action="<?php print $_SERVER["REQUEST_URI"]?>">
							<div class="box xs-options">
								<h3><?php print __('Customize XStandard','xs')?></h3>
								<p><?php print __('When customizing XStandard, please keep in mind that all changes made to the options
								 below will affect all of your users (that have editing privileges).<br />
								<!--small>(although I might add support for user/role/rights management at a later time. If your missing this feature, please report back)</small-->','xs')?></p>
								<p><?php print __('Below you can change the appearance and behaviour of XStandard.','xs')?></p>
								<ol>
									<li>
										<label for="EditorDefaultHeight"><?php print __("Editor Height","xs")?></label>
										<input class="small" id="EditorDefaultHeight" name="EditorDefaultHeight" type="text" maxlength="4" value="<?php print $_xsOptions['EditorDefaultHeight']?>" />
										<p><?php print __("Default editor height in px.","xs")?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="BackgroundColor"><?php print __("Background color","xs")?></label>
										<input id="BackgroundColor" name="BackgroundColor" type="text" maxlength="100" value="<?php print $_xsOptions['BackgroundColor']?>" />
										<p><?php print __("Type in a unicode value or use the Netscape name of a color (<samp>#CCCCCC</samp> or <samp>cornsilk</samp>).","xs")?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="BorderColor"><?php print __("Border color","xs")?></label>
										<input id="BorderColor" name="BorderColor" type="text" maxlength="100" value="<?php print $_xsOptions['BorderColor']?>" />
										<p><?php print __("Type in a unicode value or use the Netscape name of a color (<samp>#CCCCCC</samp> or <samp>cornsilk</samp>).","xs")?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="Buttons"><?php print __("Buttons XML","xs")?></label>
										<input class="full" id="Buttons" name="Buttons" type="text" maxlength="" value="<?php print $_xsOptions['Buttons']?>" />
										<p><?php print __("XStandard allows you to customize the toolbar buttons. Absolute URL or file path to buttons.xml file or XML data as a string. If absent, a built-in buttons file will be used. This file is used to change icons and define buttons for the toolbar. <a href=\"http://xstandard.com/en/documentation/xstandard-dev-guide/toolbar/buttons/\" title=\"link to the API reference\">learn more &raquo;</a>","xs")?></p>
									</li>
									<li>
										<label for="ClassImageFloatLeft"><?php print __("Left-aligned images","xs")?></label>
										<input id="ClassImageFloatLeft" name="ClassImageFloatLeft" type="text" maxlength="" value="<?php print $_xsOptions['ClassImageFloatLeft']?>" />
										<p><?php print __("Type in the class name. Images will be floated by assigning a class. You will have to take a look into your CSS-file and find the class name that reads <samp>img.classname</samp> and contains <samp>float:left</samp>","xs")?></p>
									</li>
									<li>
										<label for="ClassImageFloatRight"><?php print __("Right-aligned images","xs")?></label>
										<input id="ClassImageFloatRight" name="ClassImageFloatRight" type="text" maxlength="" value="<?php print $_xsOptions['ClassImageFloatRight']?>" />
										<p><?php print __("Type in the class name. Images will be floated by assigning a class. You will have to take a look into your CSS-file and find the class name that reads <samp>img.classname</samp> and contains <samp>float:right</samp>","xs")?></p>
									</li>
									<li>
										<label for="CSS"><?php print __("CSS","xs")?></label>
										<input class="full" id="CSS" name="CSS" type="text" maxlength="" value="<?php print $_xsOptions['CSS']?>" />
										<p><?php print __("Absolute URL or file path to a CSS file or CSS data. If absent, a built-in CSS file will be used. This file contains CSS formatting rules and can be the same CSS file used on your Web site.","xs")?></p>
									</li>
									<li>
										<label for="CustomInlineElements"><?php print __("Custom inline elements","xs")?></label>
										<input class="full" id="CustomInlineElements" name="CustomInlineElements" type="text" maxlength="" value="<?php print $_xsOptions['CustomInlineElements']?>" />
										<p><?php print __("A comma delimited list of custom elements the editor will treat as inline elements. For example: <samp>price, stock, temperature</samp>. Custom inline elements are teated like a <samp>&lt;span></samp>. Inline elements cannot contain block elements. Inline elements must be contained within a block element.","xs")?></p>
									</li>
									<li>
										<label for="CustomBlockElements"><?php print __("Custom block elements","xs")?></label>
										<input class="full" id="CustomBlockElements" name="CustomBlockElements" type="text" maxlength="" value="<?php print $_xsOptions['CustomBlockElements']?>" />
										<p><?php print __("A comma delimited list of custom elements the editor will treat as block elements. For example: <samp>include, rss</samp>. Custom block elements are treated like a <samp>&lt;div></samp> and therefore cannot be contained by <samp>&lt;p></samp>","xs")?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="CustomEmptyElements"><?php print __("Custom empty elements","xs")?></label>
										<input class="full" id="CustomEmptyElements" name="CustomEmptyElements" type="text" maxlength="" value="<?php print $_xsOptions['CustomEmptyElements']?>" />
										<p><?php print __("A comma delimited list of custom elements the editor will treat as empty elements. For example: <samp>include</samp>. Empty elements cannot contain content and are written like this: <samp>&lt;include doc=\"123\" /></samp>","xs")?></p>.
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="Debug"><?php print __("Debug mode","xs")?></label>
										<?php
										$yes_selected = $no_selected = '';
										if ($_xsOptions['Debug'] === "yes") { $yes_selected = ' selected="selected"'; } else { $no_selected = ' selected="selected"'; } ?> 
										<select id="Debug" name="Debug">
											<option value="yes"<?php print $yes_selected?>><?php print __("enable","xs")?></option>
											<option value="no"<?php print $no_selected?>><?php print __("disable","xs")?></option>
										</select>
										<p><?php print __('If debug mode is enabled, XStandard collects all kind of information about itself at runtime. <!-- You can access the information it collects on the Debugging tab of this page (TODO) --> You can see what\'s going on if you right click in the editor and choose "Editor" -> "About". You will find a register there named "Debug" which displays that information. In case the plugin shouldn\'t work as expected, you can use this feature is useful to document and submit details on your problem.','xs')?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="EditorCSS"><?php print __("Editor CSS","xs")?></label>
										<input class="full" id="EditorCSS" name="EditorCSS" type="text" maxlength="" value="<?php print $_xsOptions['EditorCSS']?>" />
										<p><?php print __('Absolute URL or file path to a CSS file or CSS data. This file contains CSS rules that are only used by the editor in WYSIWYG mode. This property is useful for locking and markers. The CSS rules can be set at run-time like this: <samp>XHTMLEditor1.EditorCSS = "h1 {-xs-lock: yes; color:red}";</samp>','xs')?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="EnableCache"><?php print __("Enable Caching","xs")?></label>
										<?php $yes_selected = $no_selected = '';
										if ($_xsOptions['EnableCache'] === "true") { $yes_selected = ' selected="selected"'; } else { $no_selected = ' selected="selected"'; } ?>
										<select id="EnableCache" name="EnableCache">
											<option value="true"<?php print $yes_selected?>><?php print __("enable","xs")?></option>
											<option value="false"<?php print $no_selected?>><?php print __("disable","xs")?></option>
										</select>
										<p><?php print __('Enabling this feature can improve XStandards Performance. You will need to make sure though you use versioned (by a unique URL) XStandard CSS and XML, XSL files. (to be honest with you, this is actually the job of the Plugin author). <a href="http://www.xstandard.com/en/documentation/xstandard-dev-guide/advanced-topics/caching/">Learn more &raquo;</a>','xs')?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="EnableTimestamp"><?php print __("Add timestamp","xs")?></label>
										<?php $yes_selected = $no_selected = '';
										if ($_xsOptions['EnableTimestamp'] === "true") { $yes_selected = ' selected="selected"'; } else { $no_selected = ' selected="selected"'; } ?>
										<select id="EnableTimestamp" name="EnableTimestamp">
											<option value="true"<?php print $yes_selected; ?>><?php print __("yes","xs")?></option>
											<option value="false"<?php print $no_selected; ?>><?php print __("no","xs")?></option>
										</select>
										<p><?php print __('This will make XStandard add a HTML comment in front of all posts. <small>The timestamp is optional. (This feature might be useful if you need to parse your valid Markup later from other domains with no DB access.)</small>','xs')?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="EnablePasteMarkup"><?php print __("Enable paste markup","xs")?></label>
										<?php $yes_selected = $no_selected = '';
										if ($_xsOptions['EnablePasteMarkup'] === "true") { $yes_selected = ' selected="selected"'; } else { $no_selected = ' selected="selected"'; } ?>
										<select id="EnablePasteMarkup" name="EnablePasteMarkup">
											<option value="true"<?php print $yes_selected?>><?php print __("yes","xs")?></option>
											<option value="false"<?php print $no_selected?>><?php print __("no","xs")?></option>
										</select>
										<p><?php print __('This option gives you control weather authors are able to paste HTML markup into the editor or not.','xs')?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="EscapeUnicode"><?php print __("Escape Unicode","xs")?></label>
										<?php $yes_selected = $no_selected = '';
										if ($_xsOptions['EscapeUnicode'] === "true") { $yes_selected = ' selected="selected"'; } else { $no_selected = ' selected="selected"'; } ?>
										<select id="EscapeUnicode" name="EscapeUnicode">
											<option value="true"<?php print $yes_selected?>><?php print __("yes","xs")?></option>
											<option value="false"<?php print $no_selected?>><?php print __("no","xs")?></option>
										</select>
										<p><?php print __('Careful with this one! This option tells XStandard that the CMS it is used with is not capable of handling UTF-8 encoding. If you have encoding problems, the problem is most likely database related.','xs')?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="ExpandWidth"><?php print __("Expand width","xs")?></label>
										<input class="small" id="ExpandWidth" name="ExpandWidth" type="text" maxlength="" value="<?php print $_xsOptions['ExpandWidth']?>" />
										<p><?php print __("Width of the Expanded mode in px or percent (for example: <samp>100%</samp>)","xs")?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="ExpandHeight"><?php print __("Expand height","xs")?></label>
										<input class="small" id="ExpandHeight" name="ExpandHeight" type="text" maxlength="" value="<?php print $_xsOptions['ExpandHeight']?>" />
										<p><?php print __("Height of the Expanded mode in px or percent (for example: <samp>100%</samp>)","xs")?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="ExpandToolbarWysiwyg"><?php print __("Expand toolbar Wysiwyg","xs")?></label>
										<input class="full" id="ExpandToolbarWysiwyg" name="ExpandToolbarWysiwyg" type="text" maxlength="" value="<?php print $_xsOptions['ExpandToolbarWysiwyg']?>" />
										<p><?php print __("Comma separated list of toolbar icons shown in the Expanded mode","xs")?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="ExpandToolbarSource"><?php print __("Expandt toolbar Source","xs")?></label>
										<input class="full" id="ExpandToolbarSource" name="ExpandToolbarSource" type="text" maxlength="" value="<?php print $_xsOptions['ExpandToolbarSource']?>" />
										<p><?php print __("Comma separated list of toolbar icons shown in the Source view of the Expanded mode","xs")?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="ExpandToolbarPreview"><?php print __("Expand toolbar Preview","xs")?></label>
										<input class="full" id="ExpandToolbarPreview" name="ExpandToolbarPreview" type="text" maxlength="" value="<?php print $_xsOptions['ExpandToolbarPreview']?>" />
										<p><?php print __("Comma separated list of toolbar icons shown in the Preview of the Expanded mode","xs")?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="ExpandToolbarScreenReader"><?php print __("Expand toolbar Screenreader","xs")?></label>
										<input class="full" id="ExpandToolbarScreenReader" name="ExpandToolbarScreenReader" type="text" maxlength="" value="<?php print $_xsOptions['ExpandToolbarScreenReader']?>" />
										<p><?php print __("Comma separated list of toolbar icons shown in the Screenreader view of the Expanded mode","xs")?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="ExpandShowStyles"><?php print __("Expand Show Styles","xs")?></label>
										<?php if ($_xsOptions['ExpandShowStyles'] === "yes") { $yes_selected = ' selected="selected"'; } else { $no_selected = ' selected="selected"'; } ?>
										<select id="ExpandShowStyles" name="ExpandShowStyles">
											<option value="yes"<?php print $yes_selected?>><?php print __("yes","xs")?></option>
											<option value="no"<?php print $no_selected?>><?php print __("no","xs")?></option>
										</select>
										<p><?php print __("Show the formats dropdown list in Expanded mode?","xs")?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="ExpandShowToolbar"><?php print __("Expand Show Toolbar","xs")?></label>
										<?php if ($_xsOptions['ExpandShowToolbar'] === "true") { $yes_selected = ' selected="selected"'; } else { $no_selected = ' selected="selected"'; } ?>
										<select id="ExpandShowToolbar" name="ExpandShowToolbar">
											<option value="true"<?php print $yes_selected?>><?php print __("yes","xs")?></option>
											<option value="false"<?php print $no_selected?>><?php print __("no","xs")?></option>
										</select>
										<p><?php print __("Display a toolbar in the Expanded mode at all?","xs")?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
									<!-- note to self: I could use this for autosave... if necessary -->
										<label for="HeartbeatURL"><?php print __("Heartbeat URL","xs")?></label>
										<input class="full" id="HeartbeatURL" name="HeartbeatURL" type="text" maxlength="" value="<?php print $_xsOptions['HeartbeatURL']?>" />
										<p><?php print __('<a href="http://www.xstandard.com/en/documentation/xstandard-dev-guide/advanced-topics/heartbeat/">Learn more &raquo;</a>',"xs")?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="HeartbeatInterval"><?php print __("Heartbeat interval","xs")?></label>
										<input class="small" id="HeartbeatInterval" name="HeartbeatInterval" type="text" maxlength="" value="<?php print $_xsOptions['HeartbeatInterval']?>" />
										<p><?php print __("Interval in seconds to execute the script given in <strong>Heartbeat URL</strong>","xs")?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="Icons"><?php print __("Icons XML","xs")?></label>
										<input class="full" id="Icons" name="Icons" type="text" maxlength="" value="<?php print $_xsOptions['Icons']?>" />
										<p><?php print __("XStandard allows you to use customized button icons. Absolute URL or file path to an icons.xml file. <a href=\"#\">Learn more</a>","xs")?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="IndentOutput"><?php print __("Indent output","xs")?></label>
										<?php if ($_xsOptions['IndentOutput'] === "yes") { $yes_selected = ' selected="selected"'; } else { $no_selected = ' selected="selected"'; } ?>
										<select id="IndentOutput" name="IndentOutput">
											<option value="yes"<?php print $yes_selected?>><?php print __("yes","xs")?></option>
											<option value="no"<?php print $no_selected?>><?php print __("no","xs")?></option>
										</select>
										<p><?php print __("Should XStandard indent the final markup? (Optional. It is done by adding additional tabs)","xs")?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="Lang"><?php print __("Language","xs")?></label>
										<input class="small" id="Lang" name="Lang" type="text" maxlength="" value="<?php print $_xsOptions['Lang']?>" />
										<p><?php print __("Set your language","xs")?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="LatestVersion"><?php print __("Latest version","xs")?></label>
										<input class="small" id="LatestVersion" name="LatestVersion" type="text" maxlength="" value="<?php print $_xsOptions['LatestVersion']?>" />
										<p><?php print __("The version number is retrieved from the makers of XStandard. When a new version is released this plugin will automatically prompt you to download the new software. Upgrading to the latest version is somewhat recommended. <strong>www.xstandard.com</strong>","xs")?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="License"><?php print __("License file","xs")?></label>
										<input class="full" id="License" name="License" type="text" maxlength="" value="<?php print $_xsOptions['License']?>" />
										<p><?php print __("Full path or URL to your XStandard License file","xs")?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="Localization"><?php print __("Localization","xs")?></label>
										<input class="full" id="Localization" name="Localization" type="text" maxlength="" value="<?php print $_xsOptions['Localization']?>" />
										<p><?php print __("Absolute URL or file path to a customized localization.xml. This file is used to translate the complete XStandard interface. This is optional and might be used in case you don't like the default translation. If left empty XStandard uses predefined texts","xs")?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="Mode"><?php print __("Default Mode","xs")?></label>
										<select id="Mode" name="Mode">
											<?php $selected = '';
											$modes = array('wysiwyg','source', 'preview', 'screen-reader');
											if (strlen($_xsOptions['Mode']) && in_array($_xsOptions['Mode'],$modes)) { $mode = $_xsOptions['Mode']; }
											foreach ($modes as $_modekey => $_modename) {
												if ($_modename === $mode) { $selected = ' selected="selected"'; }
												print '<option value="'.$_modename.'"'.$selected.'>'.ucfirst($_modename).'</option>';
											}
											?>
										</select>
										<p><?php print __('The default mode controls wether the editor opens in Wysiwyg, Source, Preview or Screenreader-mode. Wysiwyg is the default.','xs')?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="Namespaces"><?php print __("Namespaces","xs")?></label>
										<input class="full" id="Namespaces" name="Namespaces" type="text" maxlength="" value="<?php print $_xsOptions['Namespaces']?>" />
										<p><?php print __("A space separated list of custom namespaces. Adding your own namespaces like this: <samp>xmlns:a='http://apple-books' xmlns:b='http://big-books'</samp> will ad the complete namespace declaration to the corresponding elements. In source view XStandard will display something like <samp><p>Buy <a:book>Easy XHTML</a:book> from Apple Books</p></samp>","xs")?></p>
										<div class="clearfloat"></div>
									</li>
									<?php
									// reverse numeric option val to associated array
									$this->main->assoc_keys = self::$bitmaskOptions;
									$this->main->reverse_mask($_xsOptions['Options']);
									
									// Title
									$bitmaskOptionTitle[0] = __("Hard Returns.","xs");
									$bitmaskOptionTitle[1] = __("Fix Errors","xs");
									$bitmaskOptionTitle[2] = __("Context Menu.","xs");
									$bitmaskOptionTitle[3] = __("Wrap text in source.","xs");
									$bitmaskOptionTitle[4] = __("Hide Line Numbers","xs");
									$bitmaskOptionTitle[5] = __("No Resizing","xs");
									$bitmaskOptionTitle[6] = __("Decorative Images","xs");
									$bitmaskOptionTitle[7] = __("Reserved for future use.","xs");
									$bitmaskOptionTitle[8] = __("Convert extra spaces","xs");
									$bitmaskOptionTitle[9] = __("Simple Editing","xs");
									$bitmaskOptionTitle[10]= __("SOAP 1.2","xs");
									$bitmaskOptionTitle[11]= __("<samp>&lt;div></samp> behavior","xs");
									$bitmaskOptionTitle[12]= __("Directory Button","xs");
									$bitmaskOptionTitle[13]= __("Disable \"Fix\" option","xs");
									$bitmaskOptionTitle[14]= __("Auto remove elements","xs");
									$bitmaskOptionTitle[15]= __("Image as alt-text","xs");
									$bitmaskOptionTitle[16]= __("Strict mode","xs");
									$bitmaskOptionTitle[17]= __("Display the \"Class\" fields","xs");
									$bitmaskOptionTitle[18]= __("Display the \"ID\" field","xs");
									// Descriptions
									$bitmaskOptionDesc[0] = __("Display hard returns.","xs");
									$bitmaskOptionDesc[1] = __("Automatically fix errors when \"dirty\" code is loaded into the editor.","xs");
									$bitmaskOptionDesc[2] = __("Disable context menus (pop-up menus when the right mouse button is clicked).","xs");
									$bitmaskOptionDesc[3] = __("Wrap text in View Source.","xs");
									$bitmaskOptionDesc[4] = __("Hide line numbers in View Source.","xs");
									$bitmaskOptionDesc[5] = __("Disable object resizing by dragging (disables image \"handlers\", for example).","xs");
									$bitmaskOptionDesc[6] = __("Treat uploading images as decorative.","xs");
									$bitmaskOptionDesc[7] = __("Reserved for future use.","xs");
									$bitmaskOptionDesc[8] = __("Convert extra spaces into hard-spaces.","xs");
									$bitmaskOptionDesc[9] = __("Hide advanced editing features (Advanced and Custom tabs as well as certain fields in Properties dialog boxes).","xs");
									$bitmaskOptionDesc[10]= __("Use SOAP 1.2","xs");
									$bitmaskOptionDesc[11]= __("Treat <samp>&lt;div></samp> as as structure element. By default, <samp>&lt;div></samp> is used as a grouping element.","xs");
									$bitmaskOptionDesc[12]= __("Disable Directory button when content is selected.","xs");
									$bitmaskOptionDesc[13]= __("Disable \"Fix\" option when invalid markup is entered into View Source and user switches to WYSIWYG view.","xs");
									$bitmaskOptionDesc[14]= __("Automatically remove undefined custom elements. To define custom elements, use CustomInlineElements and CustomBlockElements properties.","xs");
									$bitmaskOptionDesc[15]= __("Paste images as alternate text when file upload is unavailable/disabled.","xs");
									$bitmaskOptionDesc[16]= __("Strict mode when pasting from applications like Word. Removes attributes like id, align and valign.","xs");
									$bitmaskOptionDesc[17]= __("Display the \"Class\" field on the General tab of the Properties dialog box in the simplified interface (when Options 512 is set). The only exception to this is in the Image properties dialog box when there is a value in ClassImageFloatLeft / ClassImageFloatRight properties.","xs");
									$bitmaskOptionDesc[18]= __("Display the \"ID\" field on the General tab of the Properties dialog box in the simplified interface (when Options 512 is set).","xs");
									
									$i = 0;
									$n = 0;
									//print_r($this->main->assoc_get(true));
									foreach($this->main->assoc_get(true) as $optionname => $optionval) { 
										if (isset($_POST[$optionname])) { $optionval = $_POST[$optionname]; }
										if ($optionval === "1" || $optionval == 1 || $optionval == '1') { $checked = ' checked="checked"'; } else { $checked = ''; }
										if ($optionname === "NIY") { 
											/* $n = $n; not implemented yet - don't even count */
										} else {
											$n = $n + 1;
											?>
										<li class="bmopts">
											<label for="<?php print $optionname?>"><?php print $bitmaskOptionTitle[$i]?></label>
											<input type="checkbox" id="<?php print $optionname?>" name="<?php print $optionname?>" value="1"<?php print $checked?> />
											<span><?php print $bitmaskOptionDesc[$i]?></span>
											<div class="clearfloat"></div>
										</li>
									<?php 
										}
										$i++;
									} ?>
									<li>
										<label for="Placeholders"><?php print __("Placeholders XML","xs")?></label>
										<input class="full" id="Placeholders" name="Placeholders" type="text" maxlength="" value="<?php print $_xsOptions['Placeholders']?>" />
										<p><?php print __("Absolute URL or path of a placeholders.xml. This file controls the look of placeholders in your toolbars.","xs")?></p>
										<div class="clearfloat"></div>
									</li>
																	<li>
										<label for="PreviewXSLT"><?php print __("Preview XSLT","xs")?></label>
										<input class="full" id="PreviewXSLT" name="PreviewXSLT" type="text" maxlength="" value="<?php print $_xsOptions['PreviewXSLT']?>" />
										<p><?php print __("Absolute URL or path to a preview.xsl file. This file can be used to transform your standards based markup.","xs")?></p>
										<div class="clearfloat"></div>
									</li>
																	<li>
										<label for="Rel"><?php print __("Rel attributes","xs")?></label>
										<input class="full" id="Rel" name="Rel" type="text" maxlength="" value="<?php print $_xsOptions['Rel']?>" />
										<p><?php print __("List of <samp>rel</samp> (relationship) attributes, available in the editor.","xs")?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="Rev"><?php print __("Rev attributes","xs")?></label>
										<input class="full" id="Rev" name="Rev" type="text" maxlength="" value="<?php print $_xsOptions['Rev']?>" />
										<p><?php print __("List of <samp>rev</samp> (reverse relationship) attributes, available in the editor.","xs")?></p>
									</li>
									<li>
										<label for="ScreenReaderXSLT"><?php print __("Screenreader XSLT","xs")?></label>
										<input class="full" id="ScreenReaderXSLT" name="ScreenReaderXSLT" type="text" maxlength="" value="<?php print $_xsOptions['ScreenReaderXSLT']?>" />
										<p><?php print __("Absolute URL or path to a screenreader.xsl file. This file is meant to transform your standards based markup.","xs")?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="Styles"><?php print __("Styles XML","xs")?></label>
										<input class="full" id="Styles" name="Styles" type="text" maxlength="" value="<?php print $_xsOptions['Styles']?>" />
										<p><?php print __("Absolute URL or path to a customized styles.xml file. This file controls the formats dropdown list and what precise markup each element will produce. Leran more","xs")?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="ShowStyles"><?php print __("Show Styles","xs")?></label>
										<?php if ($_xsOptions['ShowStyles'] === "true") { $yes_selected = ' selected="selected"'; } else { $no_selected = ' selected="selected"'; } ?>
										<select id="ShowStyles" name="ShowStyles">
											<option value="true"<?php print $yes_selected?>><?php print __("yes","xs")?></option>
											<option value="false"<?php print $no_selected?>><?php print __("no","xs")?></option>
										</select>
										<p><?php print __("bla","xs")?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="ShowToolbar"><?php print __("Show Toolbar","xs")?></label>
										<input id="ShowToolbar" name="ShowToolbar" type="text" maxlength="" value="<?php print $_xsOptions['ShowToolbar']?>" />
										<p><?php print __("bla","xs")?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="Toolbar"><?php print __("Toolbar","xs")?></label>
										<input id="Toolbar" name="Toolbar" type="text" maxlength="" value="<?php print $_xsOptions['Toolbar']?>" />
										<p><?php print __("bla","xs")?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="ToolbarWysiwyg"><?php print __("ToolbarWysiwyg","xs")?></label>
										<input id="ToolbarWysiwyg" name="ToolbarWysiwyg" type="text" maxlength="" value="<?php print $_xsOptions['ToolbarWysiwyg']?>" />
										<p><?php print __("bla","xs")?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="ToolbarSource"><?php print __("ToolbarSource","xs")?></label>
										<input id="ToolbarSource" name="ToolbarSource" type="text" maxlength="" value="<?php print $_xsOptions['ToolbarSource']?>" />
										<p><?php print __("bla","xs")?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="ToolbarPreview"><?php print __("ToolbarPreview","xs")?></label>
										<input id="ToolbarPreview" name="ToolbarPreview" type="text" maxlength="" value="<?php print $_xsOptions['ToolbarPreview']?>" />
										<p><?php print __("bla","xs")?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="ToolbarScreenReader"><?php print __("ToolbarScreenReader","xs")?></label>
										<input id="ToolbarScreenReader" name="ToolbarScreenReader" type="text" maxlength="" value="<?php print $_xsOptions['ToolbarScreenReader']?>" />
										<p><?php print __("bla","xs")?></p>
										<div class="clearfloat"></div>
									</li>
									<li>
										<label for="ToolbarEffect"><?php print __("ToolbarEffect","xs")?></label>
										<select id="ToolbarEffect" name="ToolbarEffect">
										<?php $effectVals = array('','linear-gradient');
										foreach ($effectVals as $effect) { 
											if ($_xsOptions['ToolbarEffect'] === $effect) { $selected=' selected="selected"'; } else { $selected = ''; }
											?>
											<option value=""<?php print $selected?>><?php if ('' === $effect) { print "none"; } else { print $effect; } ?></option>
										<?php } ?>
										</select>
									</li>

									<!-- Actually the libraries are internal stuff. Why bother plugin users with it? Anyone using it's own script?  -->
<!--
									<li>
										<label for="ImageLibraryURL"><?php print __("ImageLibraryURL","xs")?></label>
										<input id="ImageLibraryURL" name="ImageLibraryURL" type="text" maxlength="" value="<?php print $_xsOptions['ImageLibraryURL']?>" />
									</li>
									<li>
										<label for="AttachmentLibraryURL"><?php print __("AttachmentLibraryURL","xs")?></label>
										<input id="AttachmentLibraryURL" name="AttachmentLibraryURL" type="text" maxlength="" value="<?php print $_xsOptions['AttachmentLibraryURL']?>" />
									</li>
									<li>
										<label for="SpellCheckerURL"><?php print __("SpellCheckerURL","xs")?></label>
										<input id="SpellCheckerURL" name="SpellCheckerURL" type="text" maxlength="" value="<?php print $_xsOptions['SpellCheckerURL']?>" />
									</li>
-->

									<li>
										<label for="SpellCheckerLangFilter"><?php print __("SpellCheckerLangFilter","xs")?></label>
										<input id="SpellCheckerLangFilter" name="SpellCheckerLangFilter" type="text" maxlength="" value="<?php print $_xsOptions['SpellCheckerLangFilter']?>" />
									</li>
									<li>
										<label for="SpellCheckerLang"><?php print __("SpellCheckerLang","xs")?></label>
										<input id="SpellCheckerLang" name="SpellCheckerLang" type="text" maxlength="" value="<?php print $_xsOptions['SpellCheckerLang']?>" />
									</li>
									<li>
										<label for="DirectoryURL"><?php print __("DirectoryURL","xs")?></label>
										<input id="DirectoryURL" name="DirectoryURL" type="text" maxlength="" value="<?php print $_xsOptions['DirectoryURL']?>" />
									</li>
									<li>
										<label for="SubdocumentURL"><?php print __("SubdocumentURL","xs")?></label>
										<input id="SubdocumentURL" name="SubdocumentURL" type="text" maxlength="" value="<?php print $_xsOptions['SubdocumentURL']?>" />
									</li>
									<li>
										<label for="ProxySetting"><?php print __("ProxySetting","xs")?></label>
										<input id="ProxySetting" name="ProxySetting" type="text" maxlength="" value="<?php print $_xsOptions['ProxySetting']?>" />
									</li>								<li>
										<label for="ProxyServer"><?php print __("ProxyServer","xs")?></label>
										<input id="ProxyServer" name="ProxyServer" type="text" maxlength="" value="<?php print $_xsOptions['ProxyServer']?>" />
									</li>								<li>
										<label for="ProxyPort"><?php print __("ProxyPort","xs")?></label>
										<input id="ProxyPort" name="ProxyPort" type="text" maxlength="" value="<?php print $_xsOptions['ProxyPort']?>" />
									</li>								<li>
										<label for="ProxyUser"><?php print __("ProxyUser","xs")?></label>
										<input id="ProxyUser" name="ProxyUser" type="text" maxlength="" value="<?php print $_xsOptions['ProxyUser']?>" />
									</li>
								</ol>
								<div class="clearfloat"></div>
								<p>
									<input type="hidden" name="update_xsSettings" value="bla" />
									<input class="button-primary" type="submit" name="update_xstandardSettings" value="<?php print __("Save XStandard Configuration","xs")?>" />
									<input class="button" type="reset" name="restore_xstandardSettings" value="<?php print __("Restore Defaults","xs")?>" />
								</p>
							</div>
						</form>
						
					</div>
					<div class="clearboth"></div>
					
						<!-- DISPLAY THINGS FOR DEBUGGING 
						<pre>XS_EXECUTING_OS:<?php print XS_EXECUTING_OS?><br />
						XS_SYSTEM_SEPARATOR:<?php print XS_SYSTEM_SEPARATOR?><br />
						XS_PLUGINDIR_NAME:<?php print XS_PLUGINDIR_NAME?><br />
						XS_FULLPATH:<?php print XS_FULLPATH?><br />
						XS_URL:<?php print XS_URL?><br />
						XS_UPLOADPATH:<?php print XS_UPLOADPATH?><br />
						XS_WPURL:<?php print XS_WPURL?><br />
						XS_LANG:<?php print XS_LANG?><br />
						Plugin Version: <?php print $this->pluginVersion?><br />
						required WordPress Version: <?php print $this->requiredWordPressVersion?><br />
						highest tested WordPress Version: <?php print $this->highestTestedWordPressVersion?><br />
						XStandard Version included in this Plugin: <?php print $this->xstandardVersionIncluded?><br />
						XStandard Version online: <?php print $this->xstandardLatest?></pre>

<br/>
getAdminOptions()
<pre><?php // $options = $this->getAdminOptions();
	// print_r($options);
?></pre>

getXStandardOptions()
<pre><?php // $options = $this->getXStandardOptions();
	// print_r($options);
?></pre>-->
				</div><!-- end wrap div -->
<?php		} // end of option page

			function fixCode($input_code) {
				// http://www.addedbytes.com/html/on-the-fly-validation/
				$output = trim($input_code);

				if ((strpos($output, "<!DOCTYPE") > strpos($output, "<html")) or (strpos($output, "<!DOCTYPE") === false)) {
					$output = str_replace('<html', "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<html", $output);
				}

				// $output = $this->encode_chars($output);
				$output = preg_replace("/<img([^>]*)alt=([^>]*)>/im", "<img$1`alt=$2>", $output);
				$output = preg_replace("/<img([^`|>]*)>/im", "<img alt=\" \"$1>", $output);
				$output = preg_replace("/<img([^>]*)`alt=([^>]*)>/im", "<img$1alt=$2>", $output);

				if (strpos($output, "//W3C//DTD XHTML") !== false) {
					$output = preg_replace("/<(img|hr|meta|link|br|base|frame|input)([^>]*)>/mi", "<$1$2 />", $output);
					$output = preg_replace("/<(\/?)([a-z]+)( |>)/mie", "'<$1' . strtolower('$2') . '$3'", $output);
					$output = preg_replace("/<([^>]+)>/mie", "'<'.$this->process_attributes(stripslashes('$1')).'>'", $output);
					$output = preg_replace("/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w{1,8});)/i", "&", $output);
				}

				$output = str_replace("<b>", "<strong>", $output);
				$output = str_replace("<i>", "<em>", $output);
				$output = str_replace("</b>", "</strong>", $output);
				$output = str_replace("</i>", "</em>", $output);
				return $output;
			} // end of fixCode()

			function process_attributes($text) {
				return preg_replace("/ ([a-z]+)=\"([^( |\")]*)\"/mie", "' ' . strtolower('$1') . '=\"' . stripslashes('$2') . '\"'", $text);
			}

			function encode_chars($text) {
				$text = str_replace("<", "&lt;", $text);
				
				$tag_list = '((\/?)(!DOCTYPE|!--|a(bbr|cronym|ddress|pplet|rea)?|b(ase(font)?|do|ig|lockquote|ody|r|utton)?|c(aption|enter|ite|(o(de|l(group)?)))|d(d|el|fn|i(r|v)|l|t)|em|f(ieldset|o(nt|rm)|rame(set)?)|h(1|2|3|4|5|6|ead|r|tml)|i(frame|mg|n(put|s)|sindex)?|kbd|l(abel|egend|i(nk)?)|m(ap|e(nu|ta))|no(frames|script)|o(bject|l|pt(group|ion))|p(aram|re)?|q|s(amp|cript|elect|mall|pan|t(r(ike|ong)|yle)|u(b|p))|t(able|body|d|extarea|foot|h|itle|r|t)|u(l)?|var)([^>]*))';
				
				$text = preg_replace("/(&lt;)" . $tag_list . "(>)/mi", "<$2>", $text);
				$text = preg_replace("/(>[^<]*)>/mi", "$1&gt;", $text);
				$text = str_replace("/>", ">", $text);
				
				return $text;
			} // end of encode_chars()


			public function mark_post_valid() {
				// only add this meta field if we were really editing the post with xstandard
				$ref = "http://".$_SERVER['SERVER_NAME'].$_POST['_wp_http_referer'];
				$uriTokens = parse_url($ref);
				$fn = $uriTokens['path'];
				$fn = explode('/',$fn);
				$fn = $fn[count($fn)-1];
				$allowed_refs = array('post.php','post-new.php','page.php','page-new.php');
				if (in_array($fn,$allowed_refs)) {
					if (isset($_POST['post_ID'])) {
						add_post_meta( $_POST['post_ID'], 'edited_with_xstandard', "yes", true) or
						update_post_meta( $_POST['post_ID'], 'edited_with_xstandard', "yes" );
						return true;
					} else {
						return false;
					}
				}
			}


			public function _filter_conditional_wpautop() {
				global $post;
				// do we want wpautop or not?
				if ("yes" === get_post_meta($post->ID,"edited_with_xstandard",true) && !is_admin()) {
					return $post->post_content;
				} else {
					return wpautop($post->post_content);
				}
			}


		} // end of class
	} // endif;


	if (class_exists("XStandard")) {
		$xs = new XStandard(); // instantiate XStandard 
	}

	//Initialize the admin panel
	if (!function_exists("XStandardAdminPanel")) {
		function XStandardAdminPanel() {
			global $xs;
			if (!isset($xs)) {
				return;
			}
			if (function_exists('add_options_page')) {
				add_options_page('XStandard', 'XStandard', 9, basename(__FILE__), array(&$xs, 'xsOptionsPage'));
			}
		}
	}

	//Actions and Filters
	if (isset($xs)) {
		//Actions
		add_action('admin_menu', 'XStandardAdminPanel');
		add_action(__FILE__, array(&$xs, 'init'));
		add_action('save_post', array(&$xs, 'mark_post_valid')); 
		//Filters
		add_filter('edit_form_advanced', array(&$xs, '_filter_edit_form_advanced'));
		add_filter('edit_page_form', array(&$xs, '_filter_edit_form_advanced'));
		add_filter('admin_footer', array(&$xs, '_filter_js_admin_head'));
		add_filter('the_content', array(&$xs, '_filter_conditional_wpautop'),101);
		//remove_filter('the_excerpt', 'wpautop');  
		//remove_filter('the_excerpt', 'wptexturize');
		remove_filter('the_content', 'wptexturize'); // removed just for fun. needed?
		remove_filter('the_content', 'wpautop');
	}
?>
